$(function () {
    $("button[type='submit']").on("click",function () {
        $(this).attr("type","button");
        $form=$(this).parents("form");

        var url=$form.attr("action");
        if($form.attr("data-type")=='ajax'){
            $.post(url,$form.serialize(),function (re) {
                re=JSON.parse(re);
                if(re.success){
                    location.href=re.redirect;
                }
                else{
                    alert(re.error);
                }
            })
        }
    })
});